package day8;
/*
* 使用this调用构造方法
* */
public class Demo2 {
    public static void main(String[] args) {
        Student student = new Student("彭于晏",30);
    }

}
class Student{

    private String name;

    private int age;

    //无参构造
    public Student(){
        System.out.println("无参构造");
    }

    //单参构造
    public Student(String name){
        System.out.println("单参构造");
        this.name = name;
    }

    //多参构造
    public Student(String name,int age){
        //构造方法调用必须写在第一行
        //调用单参构造给name赋值
        this(name);

        this.age = age;
        System.out.println("多参构造");


    }

}
